using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;

public class CameraControl : MonoBehaviour
{
    /// <summary>
    /// 摄像机偏移
    /// </summary>
    private Vector3 CameraPosOffset;
    
    /// <summary>
    /// 摄像机移动限制
    /// </summary>
    public Rect CameraMoveLimit;
    // Start is called before the first frame update
    void Awake()
    {
        CameraPosOffset = new Vector3(-0.5f,-0.5f,-800);
    }
    
    public void MoveCamera()
    {
        this.transform.position = GetPosByGameState();
    }
    
    /// <summary>
    /// 根据游戏状态设置相机位置
    /// </summary>
    /// <returns></returns>
    public Vector3 GetPosByGameState()
    {
        var pos = SceneVariants.GetLevelManager().GetPosByGameState();
        pos = pos / 2.0f;
        return pos + CameraPosOffset;
    }
    
    /// <summary>
    /// 限制相机位置
    /// </summary>
    public void ClampCameraPos(ref Vector3 pos)
    {
        // pos.x = Mathf.Clamp(pos.x,CameraMoveLimit.xMin,CameraMoveLimit.xMax);
        // pos.y = Mathf.Clamp();
        // pos.z = Mathf.Clamp();
    }

    // Update is called once per frame
    void Update()
    {
        MoveCamera();
    }
}
